/*
 *  Copyright 2007-2008 by Matthias Buch-Kromann <mbk.isv@cbs.dk>.
 *  *
 *  This file is part of the Open-source Dependency Toolkit (OSDT),
 *  see http://code.google.com/p/open-source-dependency-toolkit.
 *  
 *  The OSDT is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 * 
 *  The OSDT is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public 
 *  License along with the OSDT in the files COPYING and COPYING.LESSER.
 *  If not, see http://www.gnu.org/licenses.
 */

package org.osdtsystem.demo;
import org.junit.Test;
import org.osdtsystem.functions.Constant;
import org.osdtsystem.functions.Function;
import org.osdtsystem.functions.FuncVariable;
import org.osdtsystem.functions.SingletonFunction;
import org.osdtsystem.values.Augmentation;
import org.osdtsystem.values.EdgeID;
import org.osdtsystem.values.Layer;
import static org.osdtsystem.functions.FunctionFactory.*;
import org.osdtsystem.values.NodeID;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class FunctionDemo {
    static SingletonFunction<Layer> DEEP = LAYER("deep");
    static SingletonFunction<Layer> SURFACE = LAYER("surface");
    
    @Test
    public static Function<Double> heightFunction() {
        System.out.println("heightDemo");
        return SUM(CONSTANT(1), MAX(
                FUNCVAL(Double.class, "height", NODES(OUT(DEEP, THISNODE))),
                CONSTANT(0.0)));
    }
    
    @Test
    public static Function<Augmentation> dependencyAugmentationFunctionForEdge() {
        System.out.println("augmentationDemo");
        FuncVariable<NodeID> dep = VARN("node");
        // AUGMENTATION FOR SIMPLE DEPENDENCY RELATION: EDGE-BASED
        FuncVariable<NodeID> gov = VARN("gov");
        FuncVariable<EdgeID> edge = VARE("edge");
        return AUGMENTATION(
            THE(edge, THISEDGE),
            THE(gov, OUTNODE(edge)),
            THE(dep, INNODE(edge)),
            GIVEN,
                SET("gov", "lex", FEATVAL("lexeme", gov)),
            NEW,
                SET("dep", "lex", FEATVAL("lexeme", dep)),
                SET("dep", "rel", FEATVAL("rel", edge))
        );
    }
    
    public static Function<Augmentation> dependencyAugmentationFunctionForNode() {
        FuncVariable<NodeID> dep = VARN("node");
        // AUGMENTATION FOR SIMPLE DEPENDENCY RELATION: NODE-BASED
        FuncVariable<NodeID> gov = VARN("gov");
        IN(DEEP,dep);
        
        return AUGMENTATION(
            THE(dep, THISNODE),
            THE(gov, OUTNODE(IN(DEEP, dep))),
            GIVEN,
                SET("gov", "lex", FEATVAL("lexeme", gov)),
            NEW,
                SET("dep", "lex", FEATVAL("lexeme", dep)),
                SET("dep", "dtype", FEATVAL("etype", dep))
        );
    }
    
    public static Function<Augmentation> adjunctDependencyAugmentationFunction() {
        FuncVariable<NodeID> dep = VARN();
        // AUGMENTATION FOR ADJUNCT RELATION
        FuncVariable<NodeID> gov = VARN();
        FuncVariable<EdgeID> edge = VARE();
        return AUGMENTATION(
            THE(edge, THISEDGE),
            THE(dep, INNODE(edge)),
            THE(gov, OUTNODE(edge)),
            GIVEN,
                SET("gov", "lex", FEATVAL("lexeme", gov)),
            NEW,
                SET("dep", "lex", FEATVAL("lexeme", dep)),
                SET("dep", "rel", FEATVAL("etype", THISEDGE)));
    }
    
    public static Function<Augmentation> complementFrameAugmentationFunction() {
        FuncVariable<NodeID> dep = VARN();
        // AUGMENTATION FOR COMPLEMENT FRAME
        FuncVariable<NodeID> gov = VARN();
        FuncVariable<EdgeID> edge = VARE();
        return AUGMENTATION(
            THE(gov, THISNODE),
            GIVEN,
                SET("gov", "lex", FEATVAL("lexeme", gov)),
                SET("gov", "word", FEATVAL("word", gov)),
            NEW,
                SET("gov", "cframe", JOINSORTED("|",
                    MAP(edge, EDGES(OUT(DEEP, gov)), FEATVAL("rel", edge)))));
    }
}
